package cn.yuanqiao.web.controller.archive.wenjianzhengli;

import cn.yuanqiao.archive.appManager.domain.TenantMdataList;
import cn.yuanqiao.archive.appManager.domain.TenantYqdaDocument;
import cn.yuanqiao.archive.wenjianzhengli.domain.Yqdatransdoc;
import cn.yuanqiao.archive.wenjianzhengli.domain.vo.YqdatransdocVo;
import cn.yuanqiao.archive.wenjianzhengli.service.ITenantYqdaDocumentService;
import cn.yuanqiao.archive.wenjianzhengli.service.IYqdatransdocService;
import cn.yuanqiao.common.utils.DateUtils;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 版式文件转换记录
 * @author zjj
 * @date 2023/9/19
 */
@RestController
@RequestMapping("/archive/toOfd")
public class YqdatransdocController extends BaseController {

    @Autowired
    private IYqdatransdocService yqdatransdocService;
    @Autowired
    private ITenantYqdaDocumentService documentService;

    @Log(title = "查询转换记录", businessType = BusinessType.SELECT)
    @PostMapping("/list")
    public TableDataInfo selectYqdatransdoc(@RequestParam("stateStr") String stateStr,@RequestParam(value="filename",required = false)String filename,@RequestParam(value="starttime",required = false)String starttime,@RequestParam(value="endtime",required = false)String endtime){
        Integer state = StringUtils.isNotEmpty(stateStr) ? Integer.valueOf(stateStr) : null;
        List<YqdatransdocVo> list = yqdatransdocService.selectYqdatransdoc(state,filename,starttime,endtime);
        return getDataTable(list);
    }

    @Log(title = "删除转换记录", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult delete(@RequestParam("docId")Long[] docId){
        yqdatransdocService.delYqdatransdoc(docId);
        return AjaxResult.success();
    }


    @Log(title = "导出版式文件转换记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void exportYqdatransdocVo(HttpServletResponse response,@RequestParam("stateStr") String stateStr,@RequestParam(value="filename",required = false)String filename,@RequestParam(value="starttime",required = false)String starttime,@RequestParam(value="endtime",required = false)String endtime)
    {
        Integer state = (StringUtils.isNotEmpty(stateStr) && !"-1".equals(stateStr)) ? Integer.valueOf(stateStr) : null;
        List<YqdatransdocVo> list = yqdatransdocService.selectYqdatransdoc(state,filename,starttime,endtime);
        ExcelUtil<YqdatransdocVo> util = new ExcelUtil<>(YqdatransdocVo.class);
        util.exportExcel(response,list, "版式文件转换记录");
    }

    @Log(title = "查询未转换记录", businessType = BusinessType.SELECT)
    @PostMapping("/selectNotYqdatransdoc")
    public TableDataInfo selectNotYqdatransdoc(@RequestParam(value="filename",required = false)String filename,@RequestParam(value="houzhui",required = false)String houzhui){
        List<TenantYqdaDocument> list = documentService.selectNotYqdatransdoc(filename,houzhui);
        return getDataTable(list);
    }
}
